package com.rich.paas.domain;


import com.rich.paas.enums.ResultCodeEnum;

import java.io.Serializable;

/**
 * restful接口统一返回实体类
 *
 * @author chenhao
 */
public class Result implements Serializable {
    private String errorMsg;
    private Object data;
    private Integer responseCode = ResultCodeEnum.SUCCESS.flag;

    public Integer getResponseCode() {
        return responseCode;
    }

    public void setResponseCode(Integer responseCode) {
        this.responseCode = responseCode;
    }

    public Result() {
    }

    public Result(Object data, String errorMsg) {
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public Result(Object data, String errorMsg, Integer responseCode) {
        this.errorMsg = errorMsg;
        this.data = data;
        this.responseCode = responseCode;
    }

    public static final Result success() {
        return new Result(null, "");
    }

    public static final Result success(Object data) {
        return new Result(data, "");
    }

    public static final Result success(Object data, String msg) {
        return new Result(data, msg);
    }

    public static final Result noPermission() {
        return new Result(null, "请先登录", ResultCodeEnum.NOT_LOGIN.flag);
    }

    public static final Result failed() {
        return new Result(null, null, ResultCodeEnum.FAILED.flag);
    }

    public static final Result failed(ResultCodeEnum codeEnum) {
        return new Result(null, "", codeEnum.flag);
    }

    public static final Result failed(String errorMsg) {
        return new Result(null, errorMsg, ResultCodeEnum.FAILED.flag);
    }

    public static final Result failed(String errorMsg, Integer responseCode) {
        return new Result(null, errorMsg, responseCode);
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public Object getData() {
        return data;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
